Summary

Explore the sigmoid function and the sharpness parameter.


In [7]:
import numpy as np
import seaborn as sns

import matplotlib.pyplot as plt

%matplotlib inline

sns.set_context('poster')

In [40]:
xplot = np.arange(-15, 15, 0.1)

In [41]:
# the sigmoid function
def sigmoid(xarr):
    return 1 / (1 + np.exp(-xplot))

In [42]:
yplot = sigmoid(xplot)

plt.figure(figsize=(8,5))
plt.plot(xplot, yplot)
plt.ylabel('p')
plt.xlabel('deltaRating')
plt.title('Sigmoid Function: y = 1 / (1 + exp(-x))')
plt.tight_layout()
plt.savefig('sigmoid_basic.png')



In [43]:
# the sigmoid function
def sigmoid_sharp(xarr, sharp):
    return 1 / (1 + np.exp(-sharp * xplot))

In [44]:
plt.figure(figsize=(8,5))
sharpnesses = [1.0, 0.25, 4.0]
for sharpness in sharpnesses:
    yplot = sigmoid_sharp(xplot, sharpness)
    plt.plot(xplot, yplot, label="sharpness = {}".format(sharpness))
plt.ylabel('p')
plt.xlabel('deltaRating')
plt.title('Effect of sharpness on Sigmoid Function')
plt.legend()
plt.tight_layout()
plt.savefig('sigmoid_sharp.png')


Normal distribution


In [45]:
mu = 0
sd = 1
norm_pdf = 1 / np.sqrt(2 * np.pi * sd ** 2) * np.exp(-(xplot - mu) ** 2 / 2 / sd ** 2)

In [47]:
plt.figure(figsize=(8,5))
plt.plot(xplot, norm_pdf)
plt.xlabel('rating')
plt.ylabel('Density')
plt.title('Prior on rating: Normal Distribution')
plt.tight_layout()
plt.savefig('prior_normal.png')



In [53]:
plt.figure(figsize=(8,5))
mus = [3, 0, -1]
sd = 1
for i, mu in enumerate(mus):
    norm_pdf = 1 / np.sqrt(2 * np.pi * sd ** 2) * np.exp(-(xplot - mu) ** 2 / 2 / sd ** 2)
    label = "Div {}, Mean = {}".format(i + 1, mu)
    plt.plot(xplot, norm_pdf, label=label)
plt.xlabel('rating')
plt.ylabel('Density')
plt.title('Prior on rating: Normal Distribution')
plt.legend()
plt.tight_layout()
plt.savefig('prior_normal_div.png')



In [51]:
1 / (1 + np.exp(-3))


Out[51]:
0.95257412682243336

In [52]:
1 / (1 + np.exp(-1))


Out[52]:
0.7310585786300049

In [ ]: